package cn.edu.jsu.nrs.model;

import java.sql.Timestamp;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.OneToMany;

import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import cn.edu.jsu.nrs.model.News;
import cn.edu.jsu.nrs.model.Reply;
import cn.edu.jsu.nrs.model.User;

/**
 * TbReply entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "tb_reply", catalog = "db_nrs")
public class Reply implements java.io.Serializable {

	// Fields

	private static final long serialVersionUID = 3168334243540727291L;
		private Integer replyId;
		private User tbUser;
		private News tbNews;
		private Reply tbReply;
		private String content;
		private Timestamp replyTime;
		private Set<Reply> tbReplies = new HashSet<Reply>(0);

		// Constructors

		/** default constructor */
		public Reply() {
		}
		
		
		/** minimal constructor */
		public Reply(News tbNews, String content, Timestamp replyTime) {
			this.tbNews = tbNews;
			this.content = content;
			this.replyTime = replyTime;
		}

		/** full constructor */
		public Reply(User tbUser, News tbNews, Reply tbReply,
				String content, Timestamp replyTime, Set<Reply> tbReplies) {
			this.tbUser = tbUser;
			this.tbNews = tbNews;
			this.tbReply = tbReply;
			this.content = content;
			this.replyTime = replyTime;
			this.tbReplies = tbReplies;
		}

		// Property accessors
		@Id
		@GeneratedValue(strategy = IDENTITY)
		@Column(name = "reply_id", unique = true, nullable = false)
		public Integer getReplyId() {
			return this.replyId;
		}

		public void setReplyId(Integer replyId) {
			this.replyId = replyId;
		}

		@ManyToOne(fetch = FetchType.LAZY)
		@JoinColumn(name = "user_id")
		public User getTbUser() {
			return this.tbUser;
		}

		public void setTbUser(User tbUser) {
			this.tbUser = tbUser;
		}

		@ManyToOne(fetch = FetchType.LAZY)
		@JoinColumn(name = "news_id", nullable = false)
		public News getTbNews() {
			return this.tbNews;
		}

		public void setTbNews(News tbNews) {
			this.tbNews = tbNews;
		}

		@ManyToOne(fetch = FetchType.LAZY)
		@JoinColumn(name = "parent_id")
		public Reply getTbReply() {
			return this.tbReply;
		}

		public void setTbReply(Reply tbReply) {
			this.tbReply = tbReply;
		}

		@Column(name = "content", nullable = false)
		public String getContent() {
			return this.content;
		}

		public void setContent(String content) {
			this.content = content;
		}

		@Column(name = "reply_time", nullable = true, length = 19)
		public Timestamp getReplyTime() {
			return this.replyTime;
		}

		public void setReplyTime(Timestamp replyTime) {
			this.replyTime = replyTime;
		}

		@OneToMany(cascade = CascadeType.REMOVE, fetch = FetchType.EAGER, mappedBy = "tbReply")
		public Set<Reply> getTbReplies() {
			return this.tbReplies;
		}

		public void setTbReplies(Set<Reply> tbReplies) {
			this.tbReplies = tbReplies;
		}

}